package com.hgk.wanwan.main.fragment.persentfragment.viewUI;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.hgk.wanwan.main.fragment.persentfragment.util.PaintOrignalView;

import width.hgk.wanwan.R;

public class GaistPlatActivity extends Activity {

    private TextView mTvshow,mTvRight,mTvAll;
    private ImageView mIvOne,mIvTwo,mIvThree;
    private Button mBtnAgain;
    private int a = 0,b = 0;
    private PaintOrignalView mPvPaint;
    private static int[]pics = {R.drawable.hongtao2,R.drawable.hongtao3,
            R.drawable.hongtao1};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gaist_plat);
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
        getWindow().setAttributes(lp);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
        initView();
       onCreanDefalt();
    }

    private void initView() {
        mTvshow = (TextView) findViewById(R.id.tv_show_content_gaist);
        mTvRight = (TextView) findViewById(R.id.tv_number_right);
        mTvAll = (TextView) findViewById(R.id.tv_number_all);
        mIvOne = (ImageView) findViewById(R.id.image_one);
        mIvThree = (ImageView) findViewById(R.id.image_three);
        mIvTwo = (ImageView) findViewById(R.id.image_two);
        mBtnAgain = (Button) findViewById(R.id.btn_play_again);
        mPvPaint = (PaintOrignalView) findViewById(R.id.pv_gaist);
        //实现洗牌方法
        randon();
        //点击时间处理
        onClick();
    }

    private void onClick() {
        mIvOne.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mIvOne.setImageDrawable(getResources().getDrawable(pics[0]));
                mIvTwo.setImageDrawable(getResources().getDrawable(pics[1]));
                mIvThree.setImageDrawable(getResources().getDrawable(pics[2]));
                mIvTwo.setAlpha(100);
                mIvThree.setAlpha(100);
                panduan(0);
            }
        });
        mIvTwo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mIvOne.setImageDrawable(getResources().getDrawable(pics[0]));
                mIvTwo.setImageDrawable(getResources().getDrawable(pics[1]));
                mIvThree.setImageDrawable(getResources().getDrawable(pics[2]));
                mIvOne.setAlpha(100);
                mIvThree.setAlpha(100);
                panduan(1);
            }
        });
        mIvThree.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mIvOne.setImageDrawable(getResources().getDrawable(pics[0]));
                mIvTwo.setImageDrawable(getResources().getDrawable(pics[1]));
                mIvThree.setImageDrawable(getResources().getDrawable(pics[2]));
                mIvTwo.setAlpha(100);
                mIvOne.setAlpha(100);
                panduan(2);
            }
        });
        mBtnAgain.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onCreanDefalt();
                mPvPaint.clear();
            }
        });
    }
    private void onCreanDefalt() {
        mIvOne.setImageDrawable(getResources().getDrawable(R.drawable.beimian));
        mIvTwo.setImageDrawable(getResources().getDrawable(R.drawable.beimian));
        mIvThree.setImageDrawable(getResources().getDrawable(R.drawable.beimian));
        mIvTwo.setAlpha(255);
        mIvOne.setAlpha(255);
        mIvThree.setAlpha(255);
        mIvOne.setEnabled(true);
        mIvThree.setEnabled(true);
        mIvTwo.setEnabled(true);
        randon();
    }

    private void panduan(int i) {
        b += 1;
        if (pics[i] == R.drawable.hongtao1) {
            a+=1;
            mTvshow.setText("恭喜你猜对了！！");
            mTvRight.setText("正确："+ a + "次");
        } else {
            mTvshow.setText("错了，要再来一次吗？");
        }
        mTvAll.setText("共" + b +"次");
        mIvOne.setEnabled(false);
        mIvThree.setEnabled(false);
        mIvTwo.setEnabled(false);
    }

    private void randon() {
        for (int i=0;i<3;i++){
            int tmp = pics[i];
            int s = (int) (Math.random()*2);
            pics[i] = pics[s];
            pics[s] = tmp;
        }
    }
    public static void launch(Context context){
        context.startActivity(new Intent(context,GaistPlatActivity.class));
    }
}
